﻿@using ECGadmin.WebUI.CustomHelpers
@using ECGadmin.WebUI.Models
@model IEnumerable<ECGadmin.Common.ViewPositionDto>
@{
    ViewBag.Title = "PositionList";
    Layout = "~/Views/Shared/_layout.cshtml";
}

<div class="toolBox">
    @Html.ToolBox(new List<object> { new Add { ClassCss = "Add", ActionName = "/Banner/AddPosition" } })
</div>
<div style="overflow:hidden;">
    <table class="table-odd table-plist">
        <colgroup>
            <col style="width: 60px" />
            <col style="width: 300px" />
            <col />
            <col />
            <col />
            <col style="width: 60px;" />
        </colgroup>
        <tr>
            <th scope="col">Thứ tự</th>
            <th scope="col">Tên vị trí</th>
            <th scope="col">Key</th>
            <th scope="col">Tên Trang</th>
            <th scope="col">Ngày tạo</th>
            <th scope="col"></th>
        </tr>
        @if (Model.Any())
        {
            var positionList = Model.OrderByDescending(m => m.PageName);
            foreach (var item in positionList)
            {
                <tr class="@string.Format("position-{0}", item.PositionId)">
                    <td>@item.Order</td>
                    <td>
                        @item.Name
                    </td>
                    <td>
                        @item.PositionKey
                    </td>
                    <td>
                        @item.PageName
                    </td>
                    <td>
                        @item.CreateDate.ToString("dd/MM/yy")
                    </td>
                    <td>
                        <a href="@Url.Action("EditPosition", "Banner", new { id = item.PositionId })" title="chỉnh sửa" class="icon-edit-v2 fl-l bootstrapTangoSmall"></a>
                        @Ajax.ActionLink("Xóa", "DeletePosition", "Banner", new { id = item.PositionId }, new AjaxOptions
                   {
                       Confirm = "Bạn chắc chắn muốn xóa position này!",
                       OnSuccess = "AjaxReturnDataDeletePosition"
                   }, new { @class = "icon-delete fl-l bootstrapTangoSmall", title = "chỉnh sửa" })
                    </td>
                </tr>
            }
        }

    </table>
</div>
    @section scripts
{
        <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
        <script type="text/javascript">

            // AJAX ------------- Xóa page
            function AjaxReturnDataDeletePosition(returnData) {
                if (returnData.result <= 0) {
                    alert('Vị trí này đã có Banner!');
                }
                else {
                    alert('Xóa thành công');
                    $('.position-' + returnData.id).remove();
                }
            }

        </script>
    }

